<?php

//Load QCubed Framework...
require_once('../../../qcubed.inc.php');

class Layout extends QForm {

    protected $objCurrentUser;
    protected $strContextMenu;

    protected $pxyLogout;

    protected function Form_Run() {
        parent::Form_Run();

        if (!isset($_SESSION['signed_in']))
            QApplication::Redirect('../membership/login.php');

        $this->objCurrentUser = unserialize($_SESSION['user']);

        if (!($this->objCurrentUser instanceof User))
            QApplication::Redirect('../membership/login.php');
    }

    protected function Form_Create() {
        parent::Form_Create();

        $this->objDefaultWaitIcon = new QWaitIcon($this);
        $this->objDefaultWaitIcon->Text = '<i class="icon-cog icon-spin icon-large"></i>';

        $this->pxyLogout = new QControlProxy($this);
        $this->pxyLogout->AddAction(new QClickEvent(), new QAjaxAction('pxyLogout_Click'));
        $this->pxyLogout->AddAction(new QClickEvent(), new QTerminateAction());
    }

    protected function Form_Validate() {
        $blnToReturn = parent::Form_Validate();

        $blnFocused = false;
        foreach ($this->GetErrorControls() as $objControl) {

            if (!$blnFocused) {
                $objControl->Focus();
                $blnFocused = true;
            }
        }
        
        return $blnToReturn;
    }

    protected function pxyLogout_Click($strFormId, $strControlId, $strParameter) {

        unset($_SESSION['signed_in']);
        unset($_SESSION['user']);

        QApplication::Redirect('../membership/login.php');
    }

}

?>